、<template>
	<div>
		<div id="postcomment">
			<h3>提交评论</h3>
			<p class="p"></p>
			<textarea placeholder="请输入您要评论的内容..." v-model="postcontent"></textarea>
			<mt-button type="primary" size="large" @click="postcomment">发表</mt-button>
		</div>
		<div id="getcomment">
			<h3>评论列表</h3>
			<p class="p"></p>
			<div v-for="(item,index) in list">
				<div class="title">
					<span>第{{index + 1}}楼:</span>
					<span>用户：{{item.user_name}}</span>
					<span>发表时间：{{item.add_time | datafmat('YYYY-MM-DD HH:mm:ss')}}</span>
				</div>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell" v-text="item.content"></li>
				</ul>
			</div>
		</div>
		<mt-button type="danger" size="large" plain @click="getmore">加载更多</mt-button>
	</div>
</template>

<script>
	export default{
		props:['id'],
		data(){
			return {
				pageindex:1,
				postcontent:'',
				list:[]
			}
		},
		created(){
			this.getcomment(this.pageindex)
		},
		methods:{
			postcomment(){
				if (this.postcontent.trim().length <= 0) {
					this.$toast('您要评论的内容不能为空');
					return
				}
				this.$http.post('http://www.lovegf.cn:8899/api/postcomment/'+this.id,{ content: this.postcontent }, { emulateJSON: true }).then(function (res) {
					this.$toast(res.body.message);
					this.list=[{
						user_name:1111,
						add_time:new Date(),
						content:this.postcontent
					}].concat(this.list);
					this.postcontent=''
				})
			},
			getcomment(pageindex){

				this.$http.get('http://www.lovegf.cn:8899/api/getcomments/'+this.id+'?pageindex='+pageindex).then(function(res){
					if(res.body.status!=0){
						this.$toast(res.body.message);
						return
					}
					this.list=this.list.concat(res.body.message)

				})
			},
			getmore(){
				this.pageindex++;
				this.getcomment(this.pageindex);

			}
		}
	}
</script>

<style scoped>
	#postcomment {
		padding: 5px;
	}

	.p {
		height: 1px;
		width: 100%;
		border-bottom: 1px solid rgba(0, 0, 0, 0.3);
	}
	#getcomment {
		padding: 5px;
	}

	.title {
		padding: 5px;
		color: #6d6d72;
		font-size: 15px;
		background-color: rgba(0, 0, 0, 0.1);
	}
</style>
